package secondStage.part4.特殊操作流;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;

/**
 * @ClassName: [ObjectInputStreamDemo]
 * @Description: 对象反序列化流
 * @Author: [黄劲松]
 * @CreateDate: [2021-04-05]
 * @Version: [v1.0]
 */
/*
4.3对象序列化流，
对象反序列化流: ObjectInputStream
    ●ObjectInputStream反序列化先前使用ObjectOutputStream编写的原始数据和对象
构造方法:
    ●ObjectInputStream(InputStreamin): 创建从指定的InputStream读取的ObjectInputStream
反序列化对象的方法: .
    ●Object readObject():从ObjectInputStream读取一 个对象
 */
public class ObjectInputStreamDemo {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("java.txt"));

        Object obj = ois.readObject();
        //向下转型
        Student s = (Student)obj;
        System.out.println(s.getName()+","+s.getAge());
        ois.close();
    }
}
